package algo.math.evaluator.context.functions;

import algo.math.evaluator.value.IValue;
import algo.math.evaluator.value.IValue.Compare;


/**
 * Minimum value between two values
 */
public class Min extends Function {

	public Min()
	{
		super._name = "min";
		super._argsNb = 2;
	}

	/* (non-Javadoc)
	 * @see algo.math.evaluator.context.functions.Function#resolve(algo.math.evaluator.value.IValue[])
	 */
	@Override
	public IValue resolve(IValue[] args) {
		
		if (args.length == super._argsNb)
		{
		if (args.length >0)
		{
			IValue min = args[0];
		
			for (IValue i : args)
			{
				if (i.compareTo(min)==Compare.INFERIOR)
				{
					min = i;
				}
			}
			return min;
		}
			return null;
			
		}
			return null;
	}
}
